<?php
session_start();
if (!isset($_SESSION['admin'])) { header('Location: index.php'); exit; }
$pid = $_GET['pid'] ?? '';
$projects = file_exists('../data/projects.json') ? json_decode(file_get_contents('../data/projects.json'), true) : [];
if (!$pid || !isset($projects[$pid])) { echo '项目不存在'; exit; }
$p = $projects[$pid];
// 分项目统计
$statFile = '../data/stat_' . $pid . '.json';
$stat = file_exists($statFile) ? json_decode(file_get_contents($statFile), true) : ['visit'=>0,'download'=>0];
// 生成二维码URL
$qr_url = '../qrcode.php?text=' . urlencode((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']!=='off'?'https':'http').'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])."/../download.php?pid=$pid");
$iconUrl = '';
$appInfoFile = '../data/project_'.$pid.'/app_info.json';
if (file_exists($appInfoFile)) {
    $appInfo = json_decode(file_get_contents($appInfoFile), true);
    if (isset($appInfo['icon']) && file_exists('../'.$appInfo['icon'])) {
        $iconUrl = '../'.$appInfo['icon'];
    }
}
if (!$iconUrl) $iconUrl = '../assets/fonts/fontawesome-webfont.svg';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title><?=$p['name']?> - 项目管理</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
    <style>
    .project-summary-card {
        box-shadow: 0 4px 18px rgba(0,0,0,0.07);
        border-radius: 18px;
        background: #fff;
        padding: 32px 24px 24px 24px;
        margin-bottom: 32px;
    }
    .project-summary-row {
        display: flex;
        flex-wrap: wrap;
        gap: 32px;
        align-items: stretch;
        justify-content: space-between;
    }
    .project-info-block, .project-qr-block, .project-stat-block {
        background: #f8f9fa;
        border-radius: 14px;
        padding: 24px 18px;
        flex: 1 1 260px;
        min-width: 220px;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    .project-info-block {
        align-items: flex-start;
    }
    .project-qr-block img {
        border-radius: 10px;
        border: 1px solid #eee;
        margin-bottom: 10px;
        background: #fff;
    }
    .project-stat-block .stat-num {
        font-size: 2.1rem;
        font-weight: bold;
        color: #007aff;
    }
    .project-stat-block .stat-label {
        color: #888;
        font-size: 1.05rem;
        margin-bottom: 10px;
    }
    @media (max-width: 900px) {
        .project-summary-row { flex-direction: column; gap: 18px; }
        .project-info-block, .project-qr-block, .project-stat-block { min-width: 0; }
    }
    .manage-btns .btn { margin-bottom: 12px; }
    .manage-btns .btn-primary { font-weight: 500; }
    .manage-btns .btn-info { color: #fff; }
    </style>
</head>
<body>
<div class="container py-5">
    <h3 class="mb-4">项目管理：<?=htmlspecialchars($p['name'])?></h3>
    <div class="project-summary-card">
        <div class="project-summary-row">
            <div class="project-info-block">
                <div class="fw-bold mb-2" style="font-size:1.2rem;">项目信息</div>
                <a href="app_info.php?pid=<?=$pid?>#icon" title="点击更换ICON">
                    <img src="<?=$iconUrl?>" class="icon-preview mb-2" style="width:56px;height:56px;object-fit:cover;border-radius:12px;border:1px solid #eee;background:#fafbfc;cursor:pointer;">
                </a>
                <div class="mb-1"><b>名称：</b><?=htmlspecialchars($p['name'])?></div>
                <div class="mb-1"><b>描述：</b><?=htmlspecialchars($p['desc'])?></div>
                <div class="mb-1"><b>语言：</b><?=($p['language']??'zh') === 'zh' ? '中文' : 'English'?></div>
            </div>
            <div class="project-qr-block text-center">
                <img src="<?=$qr_url?>" alt="二维码" style="width:120px;height:120px;cursor:pointer;" id="qr-thumb">
                <div class="small text-success mt-2">永久二维码</div>
            </div>
            <div class="project-stat-block text-center">
                <div class="stat-num mb-1"><?=$stat['visit']?></div>
                <div class="stat-label">访问量</div>
                <div class="stat-num mb-1"><?=$stat['download']?></div>
                <div class="stat-label">下载量</div>
            </div>
        </div>
    </div>
    <div class="manage-btns d-flex flex-wrap gap-2 mb-3">
        <a href="versions.php?pid=<?=$pid?>#upload" class="btn btn-success flex-fill">上传新版本</a>
        <a href="app_info.php?pid=<?=$pid?>" class="btn btn-primary flex-fill">应用信息管理</a>
        <a href="screenshots.php?pid=<?=$pid?>" class="btn btn-primary flex-fill">截图管理</a>
        <a href="versions.php?pid=<?=$pid?>" class="btn btn-primary flex-fill">历史版本管理</a>
        <a href="links.php?pid=<?=$pid?>" class="btn btn-primary flex-fill">其它链接管理</a>
        <a href="../download.php?pid=<?=$pid?>" class="btn btn-info flex-fill" target="_blank">预览下载页 (<?=($p['language']??'zh') === 'zh' ? '中文' : 'English'?>)</a>
        <?php if (($p['language']??'zh') === 'en'): ?>
        <a href="../download.php?pid=<?=$pid?>&lang=zh" class="btn btn-outline-info flex-fill" target="_blank">中文版预览</a>
        <?php else: ?>
        <a href="../download.php?pid=<?=$pid?>&lang=en" class="btn btn-outline-info flex-fill" target="_blank">English Preview</a>
        <?php endif; ?>
        <a href="projects.php" class="btn btn-outline-secondary flex-fill">返回项目列表</a>
    </div>
</div>
<!-- 二维码大图弹窗 -->
<div id="qr-modal-mask" style="display:none;position:fixed;z-index:9999;left:0;top:0;width:100vw;height:100vh;background:rgba(0,0,0,0.5);align-items:center;justify-content:center;">
    <img id="qr-modal-img" src="<?=$qr_url?>" alt="二维码大图" style="max-width:90vw;max-height:90vh;background:#fff;padding:16px;border-radius:16px;box-shadow:0 8px 32px rgba(0,0,0,0.18);">
</div>
<script>
document.getElementById('qr-thumb').onclick = function() {
    document.getElementById('qr-modal-mask').style.display = 'flex';
};
document.getElementById('qr-modal-mask').onclick = function(e) {
    if(e.target===this) this.style.display='none';
};
</script>
</body>
</html> 